<?php
	include_once "class.mysql.php";
	include_once "functions.class.php";
	include_once "functions.php";
	
	class inscription extends functions {
		var $objMysql;
	
		// Constructeur
		function inscription ($conn = false) {
			if ($conn) {
				$this->objMysql = $conn;
			}
			else {
				$this->objMysql = connexion();
			}
		}
		
		// Destructeur
		function _inscription () {
			deconnexion();
		}
		
		function newInscription ($idEleve) {
			$aUser = array ("ANNEE" => date('Y'),
							"ARABE" => 0,
							"CORAN" => 0,
							"ID_ELEVE" => $idEleve);
			
			$result = $this->objMysql->MysqlInsert(ARABE_INSCRIPTION, $aUser);
			
			if ($result) {
				return $this->objMysql->DernierID;
			}
			else {
				return false;
			}
		}
		
		function getFraisInscription ($idParent, $annee) {
			$reqGetFraisInscription = "SELECT AFI.ID_FRAIS_INSCRIPTION, AFI.ID_PARENT, AFI.ANNEE, AFI.MONTANT_DU, SUM( AP.MONTANT ) AS MONTANT_PAYE, (AFI.MONTANT_DU - SUM( AP.MONTANT )) AS RESTANT_A_PAYE
								FROM arabe_frais_inscription AFI
								INNER JOIN arabe_paiement AP ON AP.ID_FRAIS_INSCRIPTION = AFI.ID_FRAIS_INSCRIPTION
								WHERE AFI.ID_PARENT = '" . $idParent . "'
								AND AFI.ANNEE = '" . $annee . "'
								GROUP BY AFI.ID_FRAIS_INSCRIPTION";
								
			$result = $this->objMysql->MysqlSelectPerso($reqGetFraisInscription);
			if (count($result) > 0) {
				return $result;
			}
			else {
				return 0;
			}
		}
		
		function newFraisInscription ($idParent, $montantDu) {
			$values = array ("ID_PARENT" => $idParent,
                            "ANNEE" => date('Y'),
                            "MONTANT_DU" => $montantDu);

			$result = $this->objMysql->MysqlInsert("arabe_frais_inscription", $values);
			if ($result) {
				return $this->objMysql->DernierID;
			}
			else {
				return false;
			}
		}

                function updateFraisInscription ($idFraisInscription, $newMontant) {
                        $reqUpdateFraisInscription = "UPDATE arabe_frais_inscription SET MONTANT_DU = " . $newMontant . " WHERE ID_FRAIS_INSCRIPTION = '" . $idFraisInscription . "'";
			$restlt = $this->objMysql->MysqlQuery ($reqUpdateFraisInscription);

			if ($result) {
				return $newMontant;
			}
			else {
				return false;
			}
                }

                function newPaiment ($idFraisInscription, $montant, $modePaiement) {
                        $values = array ("ID_FRAIS_INSCRIPTION" => $idFraisInscription,
                                    "MONTANT" => $montant,
                                    "MODE_PAIEMENT" => $modePaiement,
                                    "DATE_PAIEMENT" => date("Y-m-d"));

			$result = $this->objMysql->MysqlInsert("arabe_paiement", $values);
			if ($result) {
				return $this->objMysql->DernierID;
			}
			else {
				return false;
			}
                }
	}
?>